package com.ku.log.util;

import com.ku.log.entity.Operator;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author: GZQ
 * @create: 2020/08/09
 * @description: 当前操作人缓存
 **/
public class OperatorCache {

    private OperatorCache(){
        throw new RuntimeException("不能实例化类型：OperatorCache.class");
    }

    private static final Map<String, Operator> CACHE = new ConcurrentHashMap<>();

    public static final Operator anonymous = Operator.builder()
            .operatorId("000000").operatorName("匿名访问者").loginName("anonymous").build();

    public static void setCache(String token, Operator operator) {
        if (null != token) {
            CACHE.put(token, operator);
        }
    }

    public static Operator getCache(String token) {
        return CACHE.getOrDefault(token, null);
    }

    public static void removeCache(String token) {
        CACHE.remove(token);
    }

    public static void clearCache() {
        CACHE.clear();
    }

}
